import torch
from torch.autograd import Variable

a = torch.randn(1, 2, 3, 4, 5)
print(a)
# number of elements
print(torch.numel(a))

# eye
print(torch.eye(5))

print(torch.linspace(1, 2, 100))

print(torch.logspace(1, 2, 10))

print(torch.ones(2, 3))
print(torch.zeros(2, 3))

print(torch.mm(torch.ones(2, 3), torch.ones(3, 2)))

print(torch.ones(torch.FloatTensor(2, 3).shape))

print(torch.arange(1, 10, 1))

# indexing, slicing, joining, mutating ops
x = torch.randn(2, 3)

# stacking by dim 0
print(torch.cat((x, x, x), 0))

# stacking by dim 1
print(torch.cat((x, x, x), 1))

# chunks
print(torch.chunk(x, 3, 1))

# gather: gather values along an axis
x = torch.FloatTensor([[1, 2], [3, 4]])
print(torch.gather(x, dim=1, index=torch.LongTensor([[0, 0], [1, 0]])))

# index select
x = torch.randn(3, 4)
indices = torch.LongTensor([0, 2])
print(torch.index_select(x, 0, indices))
print(torch.index_select(x, dim=1, index=indices))

# index mask
mask = torch.ge(x, 0.5)
print(torch.masked_select(x, mask=mask))

# nonzero
print(torch.nonzero(torch.FloatTensor([1, 1, 0, 0, 1])))
print(torch.nonzero(torch.FloatTensor([[1, 0, 0], [2, 0, 1]])))

# split
print(torch.split(torch.FloatTensor([[1, 2, 3], [4, 5, 6]]), 2, dim=1))

# squeeze: remove dim with size 1
x = torch.zeros(2, 1, 2, 1, 2)
print(x)
print(torch.squeeze(x))

x = torch.eye(2)
print(x)
print(torch.unsqueeze(x, 0))


x = torch.FloatTensor([[1, 2, 3], [4, 5, 6]])

print(x.size(0))

y = Variable(x)
print(y)
print(y.view(1, x.size(0), x.size(1)))
print(y.view(x.size(0), 1, x.size(1)))
print(y.view(x.size(0), x.size(1), 1))

